/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bookparsing;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import personal.parseInfo.TolkienParseInfo;
import personal.parser.TolkienParser;
import personal.pojo.tolkien.Book;
import personal.pojo.tolkien.Category;
import personal.utility.TolkienDBUtility;

/**
 *
 * @author PHATNBSE61057
 */
public class TolkienParsing {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        TolkienParseInfo info = new TolkienParseInfo();
        TolkienParser parser = new TolkienParser();
        parser.setWebParseInfo(info);
        List<Category> categories = new ArrayList<>();

        /*
         categories = parser.getCategories();
         for (Category category : categories) {
         category.setCategoryID("C0001");
         System.out.println(category);
         }
         TolkienDBUtility utility = new TolkienDBUtility();
         boolean result = utility.tolkienInsertCategoryIntoDB(categories);
         if (result) {
         System.out.println("Successfully");
         } else {
         System.out.println("Fail");
         }*/
        
        TolkienDBUtility utility = new TolkienDBUtility();
        categories = utility.tolkienLoadCategory();
        if (categories != null) {

            for (Category cate : categories) {
                System.out.println(cate);
            }
        } else {
            System.out.println("Nothing in database");
        }

        List<Book> books = new ArrayList<>();
        books = utility.getAllBook();
        for (Book book : books) {
            System.out.println(book);
        }
        System.out.println("There are " + books.size() + " books in bookself!!!");
        
        System.out.println("=================================================");

        List<String> bookFormats = new ArrayList<>();
        bookFormats = utility.getListBookFormat();
        for (String bookFormat : bookFormats) {
            System.out.println(bookFormat);
        }
//        List<Book> books = new ArrayList<>();
//        books = parser.getBooks(3);
//        for (Book book : books) {
//            System.out.println(book);
//        }
//
//        TolkienDBUtility dbutility = new TolkienDBUtility();
//        boolean result = dbutility.tolkienInsertBookIntoDB(books);
//        if (result) {
//            System.out.println("Successfully!!!!");
//        }
    }
}
